﻿@{
    Layout = null;
}

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <meta charset="UTF-8" />
    <title>注册</title>
    <link rel="stylesheet" href="../css/login.css" />
    <style>
        .yhzc_all {
            overflow-y: scroll;
        }

        body {
            background: #FFFFFF;
        }

        .yhzc_all_part_ul li p.pwStrength span {
            color: #fff;
        }

        .yhzc_all_part_ul li {
            position: relative;
        }

            .yhzc_all_part_ul li input {
                padding-left: 8px;
            }

        .rule {
            position: absolute;
            left: 56%;
            top: 32%;
        }

        .zc_btn {
            text-align: center;
        }
    </style>
    <script src="~/js/verifyRules.js" type="text/javascript"></script>
    <script src="/lib/jquery/jquery.min.js" charset="utf-8"></script>
     
    <script src="~/js/cookie.js"></script>
</head>

<script src="~/js/myhttp.js"></script>
<body>
    <style></style>
    <div class="yhzc_all">
        <p class="yhzc_all_title">注册</p>
        <form id="form" name="form" method="post" action="#">
            <div class="yhzc_all_part company_info">
                <div class="yhzc_all_part_title">
                    企业信息
                </div>
                <ul class="yhzc_all_part_ul">
                    <li>
                        <p><span style="color:red;">*</span>单位名称:</p>
                        <input type="text"
                               id="DepartmentName"
                               name="DepartmentName"
                               placeholder="请填写单位名称" />
                    </li>
                    @* <li>
                    <p><span style="color:red;">*</span>社会信用统一代码:</p>
                    <input type="text"
                    id="Code"
                    name="Code"
                    placeholder="请填写社会信用统一代码" />
                    </li>*@
                    <li>
                        <p><span style="color:red;">*</span>单位地址:</p>
                        <input type="text"
                               id="Address"
                               name="Address"
                               placeholder="请输入单位地址" />
                    </li>
                    @*<li>
                    <p><span style="color:red;">*</span>法人:</p>
                    <input type="text"
                    id="Representative"
                    name="Representative"
                    placeholder="请输入法人" />
                    </li>
                    *@
                    <li>
                        <p><span style="color:red;">*</span>联系人:</p>
                        <input type="text"
                               id="ContactPerson"
                               name="ContactPerson"
                               placeholder="请输入联系人" />
                    </li>
                    <li>
                        <p><span style="color:red;">*</span>联系人电话:</p>
                        <input type="text"
                               id="ContactPhone"
                               name="ContactPhone"
                               placeholder="请输入联系人电话" />
                    </li>
                </ul>
            </div>
            <div class="yhzc_all_part">
                <div class="yhzc_all_part_title">
                    用户信息
                </div>
                <ul class="yhzc_all_part_ul">
                    <li>
                        <p><span style="color:red;">*</span>登录用户名:</p>
                        <div>
                            <input type="text"
                                   id="LoginName"
                                   name="LoginName"
                                   placeholder="您的账户名和登录名" />
                        </div>
                    </li>
                    <li>
                        <p><span style="color:red;">*</span>设置密码:</p>
                        <input type="password"
                               maxlength="128"
                               id="Password"
                               name="Password"
                               placeholder="建议至少两种字符组合(8-128位)" onKeyUp=pwStrength(this.value) onBlur=pwStrength(this.value) />
                        <p class="pwStrength">
                            密码强度：<span id="strength_L" bgcolor="#eeeeee">弱</span>
                            <span id="strength_M" bgcolor="#eeeeee">中</span>
                            <span id="strength_H" bgcolor="#eeeeee">强</span>
                        </p>
                        <div class="rule">
                            <p>1.密码长度为8-128位之间</p>
                            <p>2.必须包含数字、大写字母、特殊符号</p>
                            <p>3.键盘上连续字符不能超过3位</p>
                            <p>4.连续或重复字母不能大于等于3位</p>
                            <p>5.连续或重复数字不能大于等于3位</p>
                        </div>
                    </li>
                    <li>
                        <p><span style="color:red;">*</span>确认密码:</p>
                        <input type="password"
                               maxlength="64"
                               id="SurePassword"
                               name="SurePassword"
                               placeholder="请再次输入密码" />
                    </li>

                </ul>
            </div>
            <div class="yhzc_btn">
                <input class="zc_btn"
                       type="text"
                       id="submit"
                       name="submit"
                       value="注册" />
                <p>已有账号？<a href="/">去登录</a></p>
            </div>
        </form>
        <div class="bottom"
             style="border-left-width: 0px;text-align: center;font-size: 13px">
            <div style="width:100%;">
                技术支持:qq350020527
            </div>
        </div>
    </div>
    <script src="~/js/jsencrypt.min.js"></script>
    <input id="pxkey" type="button" hidden="hidden" value="MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCLqzqTeRC4uoRx2R61hda7Y82R
TKH2bWlgWigXaz3t337p3z47jJ4c/klQOIY5XTcxf1n+nzyd5QdJLy7KX76Izg0M
MRNg8TIzjFyQqbh6P2Hx6zqh0N9SSIF9HvUcJ7XuzMQc1E1te0d9gLOG7pO58l3a
r8UYG0t3uLnqlC64mwIDAQAB" />

    <script type="text/javascript">
        $(function () {
            var IsLoading = false;
            function savesubmit(SubmitState) {


                if (IsLoading) return;
                IsLoading = true;//禁止重复提交
                var entity = Object();

                entity.Code = $('#Code').val();
                entity.Address = $('#Address').val();
                entity.Representative = $('#Representative').val();
                entity.ContactPerson = $('#ContactPerson').val();
                entity.ContactPhone = $('#ContactPhone').val();

                entity.LoginName = $('#LoginName').val();
                entity.Password = $('#Password').val();
                entity.SurePassword = $('#SurePassword').val();
                entity.DepartmentName = $('#DepartmentName').val();

                $.ajax({
                    url: "/Register/Register",
                    type: 'post',
                    dataType: 'json',
                    contentType: 'application/json',
                    data: JSON.stringify(entity),
                    async: false,
                    success: function (res) {

                        if (res == null) alert("网络有问题！");

                        if (res.code == 200) {

                            var encrypt = new JSEncrypt();
                            encrypt.setPublicKey($("#pxkey").val());

                       var     username = encrypt.encrypt(entity.LoginName);
                       var     password = encrypt.encrypt(entity.Password);

                            var login = ajaxPost("/SysPerson/UserLogin", { LoginName: username, PassWord: password });
                            if (login != null) {
                                if (login.StatusCode == "200") {

                                    var token = login.Data.Token;

                                    setCookie('Token', token, 1);

                                    //    var url = 'http://code.langben.com:801' + '/SysPerson/Index';
                                    var url = 'http://localhost:48900' + '/SysPerson/Index';
                                    var len = token.length / 200;
                                    for (let i = 0; i < len; i++) {
                                        let subStr = token.substr(0, 200);
                                        if (i == 0) {

                                            url += ('?id=' + subStr);
                                        } else {

                                            url += ('&id' + i + '=' + subStr);
                                        }
                                        token = token.replace(subStr, "");
                                    }
                                    var iframe = document.createElement('iframe');
                                    iframe.id = 'frame';
                                    iframe.name = 'frame';
                                    iframe.src = url;
                                    iframe.height = 0;

                                    document.body.insertBefore(iframe, document.body.firstChild);

                                    setTimeout(function () {
                                        window.location.href = "/Home";
                                    }, 1000);

                                }
                                else {
                                    alert("操作失败！" + login.Errors);
                                }
                            } else {
                                //btn_login
                                $('.zc_btn').addClass("layui-btn").attr("disabled", false);//取消禁用按钮状态
                            }


                        } else {
                            alert(res.msg);

                            IsLoading = false;//禁止重复提交
                            return false;
                        }
                    },
                    error: function (data) {
                        alert(JSON.stringify(data));
                        IsLoading = false;//禁止重复提交
                    }
                });



            }
            $("#submit").click(function () {
                //循环判断企业信息为必填
                var Isrequire = true;
                $('.company_info li input').map((index, item) => {

                    var _t = $(item).attr('placeholder');

                    if (!$(item).val() && Isrequire) {
                        Isrequire = false
                        alert(_t);
                        return false;
                    }

                })
                if (!Isrequire) return;


                if (!$('#LoginName').val()) {
                    alert("请输入用户名");
                    return;
                }
                if (!$('#Password').val()) {
                    alert("请输入密码");
                    return;
                }


                // var password_reg = /^(?=.*[0-9].*)(?=.*[A-Z].*)(?=.*[a-z].*)(?=.*[`~!@Html.Raw("@")#$%^&*()_\-+=<>.?:"{}].*).{8,64}$/;
                // if (!password_reg.test($('#Password').val())) {
                //     alert("密码格式错误");
                //     return;
                // }

                // if (_isKeyBoardContinuousChar($('#Password').val())) {
                //     alert("键盘上连续字符不能超过3位");
                //     return;
                // }
                // if (_isContinuousChar($('#Password').val())) {
                //     alert("输入连续字母不能有3位");
                //     return;
                // }
                // if (_isContinuousOrRepeatNum($('#Password').val())) {
                //     alert("连续或重复数字不能有3位");
                //     return;
                // }
                // if (!$('#SurePassword').val()) {
                //     alert("请再次输入密码");
                //     return;
                // }
                if ($('#SurePassword').val() != $('#Password').val()) {
                    alert("两次密码输入不一致");
                    return;
                }


                savesubmit(1);

            });




        });


        //判断输入密码的类型
        function CharMode(iN) {
            if (iN >= 48 && iN <= 57) //数字
                return 1;
            if (iN >= 65 && iN <= 90) //大写
                return 2;
            if (iN >= 97 && iN <= 122) //小写
                return 4;
            else
                return 8;
        }
        //bitTotal函数
        //计算密码模式
        function bitTotal(num) {
            modes = 0;
            for (i = 0; i < 4; i++) {
                if (num & 1) modes++;
                num >>>= 1;
            }
            return modes;
        }
        //返回强度级别
        function checkStrong(sPW) {
            if (sPW.length < 6)
                return 0; //密码太短，不检测级别
            Modes = 0;
            for (i = 0; i < sPW.length; i++) {
                //密码模式
                Modes |= CharMode(sPW.charCodeAt(i));
            }
            return bitTotal(Modes);
        }

        //显示颜色
        function pwStrength(pwd) {
            Dfault_color = "#eeeeee";        //默认颜色
            L_color = "#FF0000";        //低强度的颜色，且只显示在最左边的单元格中
            M_color = "#FF9900";        //中等强度的颜色，且只显示在左边两个单元格中
            H_color = "#33CC00";        //高强度的颜色，三个单元格都显示
            if (pwd == null || pwd == '') {
                Lcolor = Mcolor = Hcolor = Dfault_color;
            }
            else {
                S_level = checkStrong(pwd);
                switch (S_level) {
                    case 0:
                        Lcolor = Mcolor = Hcolor = Dfault_color;
                        break;
                    case 1:
                        Lcolor = L_color;
                        Mcolor = Hcolor = Dfault_color;
                        break;
                    case 2:
                        Lcolor = Mcolor = M_color;
                        Hcolor = Dfault_color;
                        break;
                    default:
                        Lcolor = Mcolor = Hcolor = H_color;
                }
            }
            document.getElementById("strength_L").style.background = Lcolor;
            document.getElementById("strength_M").style.background = Mcolor;
            document.getElementById("strength_H").style.background = Hcolor;
            return;
        }
    </script>
</body>
</html>
